/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.felinelayer.client;

import br.com.felinelayer.common.Message;
import br.com.felinelayer.common.Protocol;

/**
 *
 * @author Vanius Roberto Bittencourt
 */
public abstract class Component<T extends IComponent> implements IComponent {

    @Override
    public final void changeProperty( Message message ) {
        if ( message.isPropertyExists( Protocol.PROPERTY_NAME_WIDTH ) )
            setWidht( message.getIntByName( Protocol.PROPERTY_NAME_WIDTH ) );
        if ( message.isPropertyExists( Protocol.PROPERTY_NAME_LEFT ) )
            setLeft( message.getIntByName( Protocol.PROPERTY_NAME_LEFT ) );
        if ( message.isPropertyExists( Protocol.PROPERTY_NAME_TOP ) )
            setTop( message.getIntByName( Protocol.PROPERTY_NAME_TOP ) );
        if ( message.isPropertyExists( Protocol.PROPERTY_NAME_HEIGHT ) )
            setHeight( message.getIntByName( Protocol.PROPERTY_NAME_HEIGHT ) );
        if ( message.isPropertyExists( Protocol.PROPERTY_NAME_TEXT ) )
            setText( message.getValueByName( Protocol.PROPERTY_NAME_TEXT ) );
        doChangeProperty( message );
    }
    
    protected void doChangeProperty( Message message ) {
        
    }


    private Client client;
    
    @Override
    public final void setClient( Client client ) {
        this.client = client;
    }
    public final Client getClient() {
        return client;
    }
    
    protected void doDestroy() {
        
    }
    
    @Override
    public final void destroy() {
        setVisible( false );
        doDestroy();
        client.destroyCallBack( this );
    }
}
